package com.example.lenovo.demo.presenter.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.lenovo.demo.R;
import com.example.lenovo.demo.model.databean.CityFirstHotBean;

import java.util.List;

/**
 * Created by Lenovo on 2017/1/15.
 */

public class CityFirstHot_RvAdapter extends RecyclerView.Adapter<CityFirstHot_RvAdapter.ViewHolder> {
    private List<CityFirstHotBean.DataBean> data;
    private Context context;

    public CityFirstHot_RvAdapter(List<CityFirstHotBean.DataBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public CityFirstHot_RvAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.cityfirsthot_rvitem,parent,false));
    }

    @Override
    public void onBindViewHolder(CityFirstHot_RvAdapter.ViewHolder holder, int position) {
        holder.imageView.setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY);
        Glide.with(context).load(data.get(position).getPhoto_url())
                .into(holder.imageView);
        holder.textView1.setText(data.get(position).getTopic());
        holder.textView2.setText("-"+data.get(position).getInspiration_activities_count()+"条旅行灵感-");
    }

    @Override
    public int getItemCount() {
        return data==null?0:data.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        TextView textView1,textView2;
        public ViewHolder(View itemView) {
            super(itemView);
            imageView= (ImageView) itemView.findViewById(R.id.cityfirsthot_rvitem_img);
            textView1= (TextView) itemView.findViewById(R.id.cityfirsthot_rvitem_tv1);
            textView2= (TextView) itemView.findViewById(R.id.cityfirsthot_rvitem_tv2);
        }
    }
}
